#include <benchmark/benchmark.h>
#include "sys/select.h"
#include "sys/time.h"
#include "sys/types.h"
#include "unistd.h"
#include "util.h"

using namespace std;

static void Bm_function_Select(benchmark::State &state)
{
    struct timeval timeout;
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
    fd_set readfds, writefds;
    FD_ZERO(&readfds);
    FD_ZERO(&writefds);
    FD_SET(0, &readfds);
    FD_SET(1, &writefds);
    for (auto _ : state)
    {
        benchmark::DoNotOptimize(select(2, &readfds, &writefds, 0, &timeout));
    }
    state.SetItemsProcessed(state.iterations());
}

MUSL_BENCHMARK(Bm_function_Select);